import {reqTeamList} from "../api";

const state = {
  team:[],
  teamname: [],
  teamtable: [],
  vitorynum: [],
  defeatnum: [],
  winratenum: [],
  teammax:[],
}
const mutations = {
  GETTEAMLIST(state,team){
    state.team = team;
  }
}
const actions = {
  async getTeamList({commit}){
    let result = await reqTeamList();
    if (result){
      commit("GETTEAMLIST",result)
    }
  }
}
const getters = {
  getTeamTable(state){
     state.team.map((item)=>{
      let gTeam = []
      gTeam.push(item.clan)
      gTeam.push(item.frequency)
      gTeam.push(item.winRate)
      state.teamtable.push(gTeam)
    })
    return state.teamtable
  },
  getTeamName(state){
    state.team.map((item)=>{
      state.teamname.push(item.clan)
    })
    return state.teamname

  },
  getVicory(state){
    state.team.map((item)=>{
      state.vitorynum.push(item.victory)
    })
    return state.vitorynum
  },
  getDefeat(state){
    state.team.map((item)=>{
      state.defeatnum.push(item.defeat)
    })
    return state.defeatnum
  },
  getWinRate(state){
    state.team.map((item)=>{
      state.winratenum.push(item.winRate.replace("%",""))
    })
    return state.winratenum
  },
  getTeamMax(state){
    let maxCC = []
    let maxKill = []
    let maxEyes = []
    let one
    let two
    let three
    state.team.map((item)=>{
      maxCC.push(item.frequency)
      maxKill.push(item.totalKills)
      maxEyes.push(item.perGame)

      one = Math.max(...maxCC)
      two = Math.max(...maxKill)
      three = Math.max(...maxEyes)
    })
    state.team.map((item)=>{
      let CC = []
      for (let i in item){
        CC.push(item[i])
      }

      if (CC[2]===one){
        state.teammax.push([CC[1],one])
      }
      if(CC[6] === two){
        state.teammax.push([CC[1],two])
      }
      if(CC[7] === three){
        state.teammax.push([CC[1],three])
      }
    })
    return state.teammax
  },
}

export default {
  state,
  mutations,
  actions,
  getters
}
